function minmax(_min,_max){
return Math.random()*(_max-_min)+_min
}
// this player might just have empowered many things. or not.

function randomSelect(str, elems){
let res = "";
for (let v = 0; v<elems; v++){
res+=str[Math.round(minmax(-0.51,str.length+0.49))];
}
return res;
}

function clickPlay(){
let lists = document.getElementsByClassName("bilibili-player-iconfont");
	for (let elem of lists){
		try{
		if (elem.getAttribute("aria-label") == "播放"){elem.click();}}
			catch(e){console.log(e)}
	}
}
function clickPause(){
let lists = document.getElementsByClassName("bilibili-player-iconfont");
	for (let elem of lists){
		try{
		if (elem.getAttribute("aria-label") == "暂停"){elem.click();}}
			catch(e){console.log(e)}
	};
}
function failsafe_noplay(){
player.pause();
	clickPause();
	setTimeout(()=>{failsafe_noplay()},500)
}
function change_time(){
	let time_random = minmax(0,player.getDuration());
	player.seek(time_random);
	clickPause();
}

function createUUID() {
   return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
      var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
      return v.toString(16);
   });
}
// it will be filtered. it does not work.
function send_me_up(){
change_time();
	let content = "hello world"+createUUID();
	let event = document.createEvent("Event")
	event.initEvent("input",true,true)
let lists = document.getElementsByClassName("bilibili-player-video-danmaku-input");
for (let elem of lists){try{elem.dispatchEvent(event);setTimeout(() =>{elem.value=randomSelect(content,5)},500);setTimeout(elem.dispatchEvent(event),1000);
let buttons = document.getElementsByClassName("bilibili-player-video-btn-send");
	for (let btn of buttons){try{setTimeout(btn.click(),2000);}catch(e){console.log(e);}}
}catch(e){console.log(e)}}
setTimeout(()=>{send_me_up()},15000);
}

function main_looper(){
failsafe_noplay();
send_me_up()
}
main_looper();

